<?php
class TValidate implements TValidate_Interface, TPlugin_Interface, TPlugin_Self_Interface
{
	private $init;

	public function __call($methodName, $args){
		if(!isset($this->init)){
			TControllerConf::init();
			$this->init = true;
		}
		if(strlen(TValidateConf::METHOD_HEAD) == 0){
			return false;
		}
		if(strpos($methodName, TValidateConf::METHOD_HEAD) !== 0){
			return false;
		}
		$class = str_replace(TValidateConf::METHOD_HEAD, '', $methodName);
		$class.= "Validate";
		if(!class_exists($class)){
			if(is_readable(TValidateConf_METHOD_DIR.DS.$class.'.php')){
				include_once(TValidateConf_METHOD_DIR.DS.$class.'.php');
			}else{
				return false;
			}
		}
		if(!isset($this->obj[$class])){
			$this->obj[$class] = new $class;
			if(!($this->obj[$class] instanceof TValidateMethod_Interface)){
				return false;
			}
		}
		return $this->obj[$class]->action($args);
	}
}
